Ext.onReady(function(){ 

Ext.QuickTips.init();
Ext.form.Field.prototype.msgTarget = 'under';
  

var fm = Ext.form;

//Gridpanel
var cm=new Ext.grid.ColumnModel([
{header:'流水号',dataIndex:'serialNo',hidden:true,
editor: new fm.TextField({allowBlank: false,editable:false,readOnly:true})
} ,
{header:'大类因素',
	sortable: true, renderer: function (value, meta, record, rowIndex, colIndex, store) {
                    var first = !rowIndex || value !== store.getAt(rowIndex - 1).get('describe1'),
                        last = rowIndex >= store.getCount() - 1 || value !== store.getAt(rowIndex + 1).get('describe1');
                    meta.css += 'row-span' + (first ? ' row-span-first' : '') +  (last ? ' row-span-last' : '');
                    if (first) {
                        var i = rowIndex + 1;
                        while (i < store.getCount() && value === store.getAt(i).get('describe1')) {
                            i++;
                        }
                        var rowHeight = 20, padding = 6,
                            height = (rowHeight * (i - rowIndex) - padding) + 'px';
                        meta.attr = 'style="height:' + height + ';line-height:' + height + ';"';
                    }
                    return first ? '<b>'+value+'</b><br>' : '';
                }, 
	dataIndex:'describe1',
	width:80
    },
{header:'子类因素',
			sortable: true, renderer: function (value, meta, record, rowIndex, colIndex, store) {
                    var first = !rowIndex || value !== store.getAt(rowIndex - 1).get('describe2'),
                        last = rowIndex >= store.getCount() - 1 || value !== store.getAt(rowIndex + 1).get('describe2');
                    meta.css += 'row-span' + (first ? ' row-span-first' : '') +  (last ? ' row-span-last' : '');
                    if (first) {
                        var i = rowIndex + 1;
                        while (i < store.getCount() && value === store.getAt(i).get('describe2')) {
                            i++;
                        }
                        var rowHeight = 20, padding = 6,
                            height = (rowHeight * (i - rowIndex) - padding) + 'px';
                        meta.attr = 'style="height:' + height + ';line-height:' + height + ';"';
                    }
                    return first ? value : '';
                }, 
		dataIndex:'describe2',
		width:80,
		
},

//{header:'',
//dataIndex:'operation',
//renderer: function (value, meta, record) {  
//    //在这里定义了3个操作,分别赋予不同的css class以便区分  
//    var formatStr = "<input name='c' type='checkbox' id='c' value='1'/>";  
//    var resultStr = String.format(formatStr, record.get('id'), record.get('id'), record.get('id'));  
//    return "<div class='controlBtn'>" + resultStr + "</div>";  
//  }.createDelegate(this),  
//  css: "text-align:center;",
//  width:10,
//	
//},

{header:'财务报表项值',
dataIndex:'itemValue',
width:40
},
{header:'因素说明',
	sortable: true, renderer: function (value, meta, record, rowIndex, colIndex, store) {
                    var first = !rowIndex || value !== store.getAt(rowIndex - 1).get('describe3'),
                        last = rowIndex >= store.getCount() - 1 || value !== store.getAt(rowIndex + 1).get('describe3');
                    meta.css += 'row-span' + (first ? ' row-span-first' : '') +  (last ? ' row-span-last' : '');
                    if (first) {
                        var i = rowIndex + 1;
                        while (i < store.getCount() && value === store.getAt(i).get('describe3')) {
                            i++;
                        }
                        var rowHeight = 20, padding = 6,
                            height = (rowHeight * (i - rowIndex) - padding) + 'px';
                        meta.attr = 'style="height:' + height + ';white-space:normal;"';
                    }
                    return first ? value : '';
                },
dataIndex:'describe3',
width:200
},

]); 

var ds = new Ext.data.Store({ 
proxy:new Ext.data.HttpProxy({
url:'rating/listModelItems.do?dataFlag=1',
method:'POST'
}), 
reader:new Ext.data.JsonReader({ 
totalProperty:'total',  
root:'resultData'},[
{name:'serialNo'},
{name:'describe1'}, 
{name:'describe2'},  
{name:'describe3'},
{name:'itemDescribe'},
{name:'itemValue'},
{name:'reportItemValue'},
{name:'itemWeight'}
]) 
}); 
ds.load(); 


var grid=new Ext.grid.EditorGridPanel({ 
id:'myCustomers',
stripeRows:true,//斑马线效果
title:'<div align="center">定量因素</div>', 
height:300, 
cm:cm,
store: ds, 
clicksToEdit: 1,
columnLines:true, 
cls: 'grid-row-span',
loadMask: { msg: "加载中..." }, 
viewConfig: {   
                            forceFit:true   
            }  
                      
});

function afterEdit(obj){    //每次更改后，触发一次该事件  
	var row = obj.record;
	var col = obj.field;
	//alert(row.data.serialNo);
	//alert(col);
   //alert("orginalValue:"+obj.originalValue+",value:"+obj.value);  
   
	Ext.Ajax.request({
		url:'model/editRatio.do?dataFlag=1',
		params : { serialNo: row.data.serialNo,
			field:col, 
			describe2:row.data.describe2,
			originalValue:obj.originalValue, 
			modifiedValue:obj.value
		},
		method:'POST',
		success:function(){
			Ext.MessageBox.alert("提示","修改成功！");
			grid.store.reload(); 
		},failure:function(){
			Ext.MessageBox.alert("提示", "修改失败！"); 
		}
	});
 
}  
grid.on("afteredit", afterEdit, grid);  

var panel =  new Ext.Panel({
renderTo:"panel",
items:[grid]
});

});


function save111(){
	Ext.MessageBox.alert("提示","保存成功！");
};
